/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogHeaderTrace.java
 *
 * Created on 10/06/2010, 14:59:51
 */
package botoseis.iview.dialogs;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import botoseis.iview.main.MainWindow;
import usrdata.SUHeader;

/**
 *
 * @author gabriel
 */
public class DialogHeaderTrace extends javax.swing.JDialog {

    /** Creates new form DialogHeaderTrace */
    public DialogHeaderTrace(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setPreferredSize(new Dimension(400, 600));
        setTitle("Trace Header");
        this.getRootPane().getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "fecharJanela");
        this.getRootPane().getActionMap().put("fecharJanela", new AbstractAction("fecharJanela") {

            public void actionPerformed(ActionEvent evt) {
                dispose();

            }
        });
    }

    public void initPanel() {
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pHeader = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbHeaders = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        pHeader.setLayout(new java.awt.GridLayout(1, 1));

        tbHeaders.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "ID", "Value", "Description"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbHeaders.setColumnSelectionAllowed(true);
        jScrollPane1.setViewportView(tbHeaders);
        tbHeaders.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        tbHeaders.getColumnModel().getColumn(0).setMinWidth(50);
        tbHeaders.getColumnModel().getColumn(0).setPreferredWidth(50);
        tbHeaders.getColumnModel().getColumn(0).setMaxWidth(50);

        pHeader.add(jScrollPane1);

        getContentPane().add(pHeader, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        float[] x = new float[0];
        float[] y = new float[0];
        ((MainWindow) getParent()).getmHeader().update(x, y);
        ((MainWindow) getParent()).getGfxPanelCDP().repaint();
    }//GEN-LAST:event_formWindowClosed

    public void updateHeaders(SUHeader header) {
        String[] col = {"ID", "Value", "Description"};
        DefaultTableModel dm = new DefaultTableModel(col, 0) {

            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        Object[] row = new Object[3];

        row[0] = "TRACL";
        row[1] = header.tracl;
        row[2] = "Trace sequence number within line";
        dm.addRow(row);

        row[0] = "TRACR";
        row[1] = header.tracr;
        row[2] = "Trace sequence number within reel";
        dm.addRow(row);

        row[0] = "FLDR";
        row[1] = header.fldr;
        row[2] = "Field record number";
        dm.addRow(row);

        row[0] = "TRACF";
        row[1] = header.tracf;
        row[2] = "Trace number within field record";
        dm.addRow(row);

        row[0] = "EP";
        row[1] = header.ep;
        row[2] = "Energy source point number";
        dm.addRow(row);

        row[0] = "CDP";
        row[1] = header.cdp;
        row[2] = "CDP ensemble number";
        dm.addRow(row);

        row[0] = "CDPT";
        row[1] = header.cdpt;
        row[2] = "Trace number within CDP ensemble";
        dm.addRow(row);

        row[0] = "OFFSET";
        row[1] = header.offset;
        row[2] = "Distance from source point to receivergroup";
        dm.addRow(row);

        row[0] = "SX";
        row[1] = header.sx;
        row[2] = "X source coordinate";
        dm.addRow(row);

        row[0] = "SY";
        row[1] = header.sy;
        row[2] = "Y source coordinate";
        dm.addRow(row);

        row[0] = "GX";
        row[1] = header.gx;
        row[2] = "X group coordinate";
        dm.addRow(row);

        row[0] = "GY";
        row[1] = header.gy;
        row[2] = "Y group coordinate";
        dm.addRow(row);

        row[0] = "DELRT";
        row[1] = header.delrt;
        row[2] = "Delay recording time, time in ms";
        dm.addRow(row);

        row[0] = "NS";
        row[1] = (int) header.ns;
        row[2] = "Number of samples in this trace";
        dm.addRow(row);

        row[0] = "DT";
        row[1] = (int) header.dt;
        row[2] = "Sample interval; in micro-seconds";
        dm.addRow(row);

        row[0] = "D1";
        row[1] = header.d1;
        row[2] = "Sample spacinf for non-seismic data";
        dm.addRow(row);

        row[0] = "F1";
        row[1] = header.f1;
        row[2] = "Frist sample location for non-sesmic data";
        dm.addRow(row);

        row[0] = "D2";
        row[1] = header.d2;
        row[2] = "Sample spacing between traces";
        dm.addRow(row);

        row[0] = "F2";
        row[1] = header.f2;
        row[2] = "Frist trace location";
        dm.addRow(row);

        row[0] = "NTR";
        row[1] = header.ntr;
        row[2] = "Number of traces";
        dm.addRow(row);

        row[0] = "GELEV";
        row[1] = header.gelev;
        row[2] = "Receiver group elevation from sea level";
        dm.addRow(row);

        row[0] = "SELEV";
        row[1] = header.selev;
        row[2] = "Source group elevation from sea level";
        dm.addRow(row);

        row[0] = "SSTAT";
        row[1] = header.sstat;
        row[2] = "Source static correction in milliseconds.";
        dm.addRow(row);

        row[0] = "GSTAT";
        row[1] = header.gstat;
        row[2] = "Group static correction in milliseconds.";
        dm.addRow(row);

        row[0] = "TSTAT";
        row[1] = header.tstat;
        row[2] = "Total static applied  in milliseconds.";
        dm.addRow(row);
        
        row[0] = "SDEPTH";
        row[1] = header.sdepth;
        row[2] = "Source depth (positive)";
        dm.addRow(row);

        row[0] = "GDEL";
        row[1] = header.gdel;
        row[2] = "Datum elevation at receiver group";
        dm.addRow(row);

        row[0] = "SDEL";
        row[1] = header.sdel;
        row[2] = "Datum elevation at source";
        dm.addRow(row);

        row[0] = "SWDEP";
        row[1] = header.swdep;
        row[2] = "Water depth at source";
        dm.addRow(row);

        row[0] = "GWDEP";
        row[1] = header.gwdep;
        row[2] = "Water depth at group";
        dm.addRow(row);

        tbHeaders.setModel(dm);
        tbHeaders.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tbHeaders.setColumnSelectionAllowed(false);
        tbHeaders.setShowGrid(false);
        tbHeaders.getColumnModel().getColumn(0).setMinWidth(55);
        tbHeaders.getColumnModel().getColumn(0).setMaxWidth(55);
        tbHeaders.getColumnModel().getColumn(1).setMinWidth(100);
        tbHeaders.getColumnModel().getColumn(1).setMaxWidth(100);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                DialogHeaderTrace dialog = new DialogHeaderTrace(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pHeader;
    private javax.swing.JTable tbHeaders;
    // End of variables declaration//GEN-END:variables
}
